package 比屋作业.day18;
import java.util.*;
public class D18_3 {
    public static void main(String[] args) {
    List<Product> products=new ArrayList<>();
    products.add(new Product("洗衣机",1500.0));
    products.add(new Product("冰箱",2000));
    products.add(new Product("电视",3000));
    products.add(new Product("手机",5000));
    products.add(new Product("电脑",7000));
        System.out.println("按照价格升序排列：");
        Collections.sort(products);
        for (Product product:products){
            System.out.println(product);
        }
        System.out.println("按照价格升序排列：");
        Collections.sort(products,Collections.reverseOrder());
        for (Product product:products){
            System.out.println(product);
        }
    }
}
class Product implements Comparable<Product>{
    private String name;
    private  double price;
    public Product(String name,double price){
        this.name=name;
        this.price=price;
    }
    public String getName() {
        return name;
    }
    public double getPrice() {
        return price;
    }

    @Override
    public String toString() {
        return "Product(name="+name+",price="+price+")";
    }

    @Override
    public int compareTo(Product other) {
        return
                Double.compare(this.price,other.price);
    }
}
